package lucene.IKAnalyzer5x;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.synonym.SynonymFilterFactory;
import org.apache.lucene.analysis.util.ClasspathResourceLoader;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class IKSynonymsAnalyzer5x extends Analyzer {
    @Override
    protected TokenStreamComponents createComponents(String fieldName) {
        IKTokenizer5x tokenizer5x = new IKTokenizer5x(true);
        Map paramsMap=new HashMap();
        paramsMap.put("luceneMatchVersion", "LUCENE_11");
        paramsMap.put("synonyms", "luceneIndexCreate/synonyms.txt");
        paramsMap.put("expand", "true");
        SynonymFilterFactory factory=new SynonymFilterFactory(paramsMap);
        ClasspathResourceLoader loader = new ClasspathResourceLoader();
        try {
            factory.inform(loader);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new TokenStreamComponents(tokenizer5x, factory.create(tokenizer5x));
    }
}
